
<?
	  include("/inc/header.html") {}
    ?>    

                            <div class="panel panel">          
                                <div class="panel-body pan">
                                        <div class="form-body pal">
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                     <label for="inputUsername" >中文名称 <span class='require'>*</span> </label>
                                                        <div class="input-icon right">
                                                            <input id="nameZh" type="text" class="form-control" onchange="pinYin(this.value)"/>
                                                        </div>
                                                    </div>
                                                </div>
                                                 <div class="col-md-6">
                                                    <div class="form-group">
                                                     <label for="inputUsername" >英文名称 <span class='require'>*</span> </label>
                                                        <div class="input-icon right">
                                                          <input id="nameEn" type="text" class="form-control" onchange="voluation(this.value);"/>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <div class="input-icon right">   
                                                         <label for="inputUsername" >字段名称 <span class='require'>*</span> </label>
                                                            <input id="field" type="text" class="form-control"  readonly="readonly"/>
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group">
                                                        <div class="input-icon right">
                                                         <label for="inputUsername" >排序 <span class='require'>*</span> </label>
                                                            <input id="sort" type="text" class="form-control" />
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                           
                                                 <hr/>
                                              <div class="row">
                                                <div class="col-md-6">
                                                    <div class="form-group"><label for="inputUsername" >是否多值 <span class='require'>*</span> </label>
                                                        <select  id="multiValued"  class="form-control">
                                                             <option value="1">true</option>
                                                             <option value="0">false</option>
                                                        </select>    
                                                    </div>                                                   
                                                </div>
                                                <div class="col-md-6">
                                                    <div class="form-group"><label for="inputUsername" >是否必填 <span class='require'>*</span> </label>
                                                        <select  id="required"  class="form-control">
                                                             <option value="1">true</option>
                                                             <option value="0">false</option>
                                                        </select>    
                                                    </div>                                                   
                                                </div>
                                                 <div class="col-md-6">
                                                    <div class="form-group"><label for="inputUsername" >是否内容存储 <span class='require'>*</span> </label>
                                                        <select  id="stored"  class="form-control">
                                                             <option value="1" selected>true</option>
                                                             <option value="0">false</option>
                                                        </select>    
                                                    </div>                                                   
                                                </div>
                                                 <div class="col-md-6">
                                                    <div class="form-group"><label for="inputUsername" >是否建立索引<span class='require'>*</span> </label>
                                                        <select  id="indexed"  class="form-control">
                                                             <option value="1" selected>true</option>
                                                             <option value="0">false</option>
                                                        </select>    
                                                    </div>                                                   
                                                </div>
                                                 <div class="col-md-6">
                                                    <div class="form-group"><label for="inputUsername" >是否用作特性 <span class='require'>*</span> </label>
                                                        <select  id="termVectors"  class="form-control">
                                                             <option value="1">true</option>
                                                             <option value="0">false</option>
                                                        </select>    
                                                    </div>                                                   
                                                </div>
                                            </div>
                                        </div>
                                </div>
                            </div>   
                     
                    
                    
                       
    
  <script>
  
var index1 = window.parent.getlay();
 $("#id").val(index1);
 $(function(){
 if(index1!=0){
 	demo1();
 }
	
}); 
	
function Page() {   

          if($.trim($("#sort").val()).length<1) {
    	        	alert('排序不能为空！');
    	        	return null;
    	        }
    	        if(isNaN($("#sort").val())){
                  alert("必须是数字");
                  return null;
                   }
    $.ajax({  
                type : "post",  
                url : "./KnowledgeCommonObjectsave.do",  
                data : {"id":index1,"nameEn":$("#nameEn").val(),"nameZh":$("#nameZh").val(),"sort":$("#sort").val()
          ,"field":$("#field").val(),"multiValued":$("#multiValued").val(),"required":$("#required").val(),"stored":$("#stored").val(),"indexed":$("#indexed").val(),"termVectors":$("#termVectors").val()},
                dataType : "json", 
                async:false,  
                success : function(data) { 
                    var index = parent.layer.getFrameIndex(window.name); 
		            window.parent.get();
		            parent.layer.msg('添加或编辑成功');
		            parent.layer.close(index); 
                },
	            error : function(data) {
                   alert("请求失败");
		        }
            });

          
    }  
 
   function demo1(){
    $.getJSON('./KnowledgeCommonObjectedit.do', {
        id: index1 //向服务端传的参数，此处只是演示
    }, function(res){
        //此处仅仅是为了演示变化的内容
        $("#nameEn").val(res[0].nameEn);
        $("#nameZh").val(res[0].nameZh);
        $("#field").val(res[0].field);
         $("#sort").val(res[0].sort);
       selected("multiValued",res[0].multiValued);
	   selected("required",res[0].required);
	   selected("stored",res[0].stored);
	   selected("indexed",res[0].indexed);
	   selected("termVectors",res[0].termVectors);
		document.getElementById('nameEn').disabled = true;
    });
};
function selected(selectname,selectid)
{
 $("#"+selectname+" option").each(function(){ //遍历全部option
	      var v = $(this).val(); //获取option的内容
	      if(v == selectid){
	        $(this).attr("selected","selected");
	      }
	}); 
}

	function voluation(name) {
		if ($.trim(name).length < 1) {
			alert('英文名不能为空！');
			return null;
		}
		if ($.trim(name).length > 32) {
			alert('英文名长度过长！');
			$("#nameEn").val("");
			$("#field").val("");
			return null;
		}
		$.ajax({
			type : "post",
			url : "./KnowledgeCommonObjectPropertyProving.do",
			data : {
				"name" : name,
			},
			async : false,
			dataType : "json",
			success : function(data) {
				if (data.result != 1) {
					alert("表名不可用，重命名或者不符合规则");
					$("#nameEn").val("");
				}else{
					$("#nameEn").val("op_"+name);
				}

			},
			error : function(data) {
				alert("请求失败");
			}
		});
  $("#field").val($("#nameEn").val());
	}
	//汉字转拼音
  function pinYin(pinyinName){
   if(index1==0){
		$.ajax({
			type : "post",
			url : "hanziToinitial.do",
			data : {
				"pinYin" : pinyinName,
			},
			async : false,
			dataType : "json",
			success : function(data) {
			if(data[0].length > 32){
					layer.msg('自动转换英文名长度过长!请手动输入！');
					$("#nameEn").val("");
					$("#field").val("");
				}else{
					$("#nameEn").val("op_"+data);
					$("#field").val("op_"+data);
				}
			},
			error : function(data) {
				alert("请求失败");
			}
		});
		}
	}
</script>


